
package com.tool.btn;

import com.tool.role.RoleData;
import com.tool.role.RoleProperty;
import com.tool.tcpimg.UIUtils;
import java.awt.Color;
import java.awt.Font;
import java.awt.event.MouseEvent;
import java.math.BigDecimal;

import come.tool.Fighting.FightingMixDeal;
import come.tool.JDialog.TiShiUtil;
import come.tool.handle.HandleState;
import org.come.Frame.*;
import org.come.Jpanel.PartnerMainJpanel;
import org.come.bean.LoginResult;
import org.come.entity.Baby;
import org.come.entity.Pal;
import org.come.model.PalData;
import org.come.model.Pet;
import org.come.socket.Agreement;
import org.come.socket.SendMessageUntil;
import org.come.until.UserMessUntil;
import org.come.until.Util;

public class BabyBtn extends MoBanBtn {
    private int caozuo;

    public BabyBtn(String iconpath, int type, String text) {
        super(iconpath, type);
        this.setText(text);
        this.setFont(UIUtils.TEXT_FONT1);
        this.setForeground(Color.yellow);
        this.setVerticalTextPosition(0);
        this.setHorizontalTextPosition(0);
    }

    public BabyBtn(String iconpath, int type) {
        super(iconpath, type);
    }

    public BabyBtn(String iconpath, int type, Color[] colors, Font font, String text) {
        super(iconpath, type, colors);
        this.setText(text);
        this.setFont(font);
        this.setVerticalTextPosition(0);
        this.setHorizontalTextPosition(0);
    }



    public void chooseyes() {
    }

    @Override
    public void chooseno() {
    }

    @Override
    public void nochoose(MouseEvent e) {
        Baby baby = UserMessUntil.getbaby(TestChildJframe.getTestChildJframe().getTestChildJpanel().getBabyid());
        if (baby == null) {
            ZhuFrame.getZhuJpanel().addPrompt2("你没有选中的孩子");
        }
        LoginResult loginResult = RoleData.getRoleData().getLoginResult();
        if (this.getText().equals("寄养")) {
            if(loginResult.getBabyId()!=null) {
                ZhuFrame.getZhuJpanel().addPrompt2("宝宝已参战不能寄养！");
                return;
            }
            if(baby.getState() == null || !baby.getState().equals("1")) {
                /**判断是否解锁*/
                if(Util.isCanBuyOrno()){
                    return;
                }
                PartnerMainJpanel mainJpanel = PartnerJframe.getPartnerJframe().getPartnerMainJpanel();
                if (mainJpanel.getPalDataChooseId() < 0) {
                    ZhuFrame.getZhuJpanel().addPrompt2("请选择一个伙伴");
                    return;
                }
                Pal pidGetPal = mainJpanel.pidGetPal(mainJpanel.getPalDataChooseId());
                if (pidGetPal == null) {
                    ZhuFrame.getZhuJpanel().addPrompt2("请选中一个伙伴");
                    return;
                }
                PalData palData = UserMessUntil.getPalData(pidGetPal.getpId());
                String name = palData.getName();
                if(pidGetPal.getBaby()!=null) {
                    ZhuFrame.getZhuJpanel().addPrompt2("伙伴【#G"+name+"#Y】已寄养了孩子，请先取回");
                    return;
                }
                StringBuffer buffer = new StringBuffer();
                buffer.append("#Y你是否要将孩子#R");
                buffer.append(baby.getBabyname());
                buffer.append("#Y寄养给伙伴#G"+name);
                OptionsJframe.getOptionsJframe().getOptionsJpanel().showBox(TiShiUtil.palToBaby, baby, buffer.toString());
            }else {
                ZhuFrame.getZhuJpanel().addPrompt2("孩子已被寄养，请先取回");
            }
        } else if (this.getText().equals("取回")) {
            PartnerMainJpanel mainJpanel = PartnerJframe.getPartnerJframe().getPartnerMainJpanel();
            int chooseId = mainJpanel.getPalDataChooseId();
            if (chooseId > 0) {
                Pal pidGetPal = mainJpanel.pidGetPal(chooseId);
                if(pidGetPal.getBaby()!=null) {
                    if(pidGetPal.getBaby()!=null) {
                        /**判断是否解锁*/
                        if(Util.isCanBuyOrno()){
                            return;
                        }
                        PalData palData = UserMessUntil.getPalData(pidGetPal.getpId());
                        String name = palData.getName();
                        OptionsJframe.getOptionsJframe().getOptionsJpanel().showBox(TiShiUtil.palGetBaby, pidGetPal.getBaby(),"#W确定要将给伙伴"+name+"寄养的BABY:#G"+pidGetPal.getBaby().getBabyname()+"#W领回吗?");
                    }
                }else {
                    ZhuFrame.getZhuJpanel().addPrompt2("你没有寄养给该伙伴BABY！");
                }
            }else {
                ZhuFrame.getZhuJpanel().addPrompt2("请先选中一个伙伴");
            }
        }


        else {
            if ("跟随".equals(this.getText())) {
                this.setText("取消");
            } else if ("取消".equals(this.getText())) {
                this.setText("跟随");
            } else {
                String mes;
                if(baby.getState()!=null && baby.getState().equals("1")) {
                    ZhuFrame.getZhuJpanel().addPrompt2("这个熊孩子已被寄养，无法和你参战！");
                }else {
                    if("寄养".equals(this.getText())){
                        this.setText("取回");
                    }else if("取回".equals(this.getText())){
                        this.setText("寄养");
                    }
                    if ("待机".equals(this.getText())) {
                        loginResult.setBabyId(null);
                        RoleProperty.ResetBaby(null);
                        this.setText("参战");
                        mes = Agreement.getAgreement().rolechangeAgreement("B");
                        SendMessageUntil.toServer(mes);
                    } else if ("参战".equals(this.getText())) {
                        RoleProperty.ResetBaby(baby);
                        loginResult.setBabyId(baby.getBabyid());
                        this.setText("待机");
                        mes = Agreement.getAgreement().rolechangeAgreement("B" + baby.getBabyid());
                        SendMessageUntil.toServer(mes);
                    }
                }
            }
        }
    }
}
